<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>PhotoSphereViewer - little planet demo</title>

        <link rel="stylesheet" href="/dist/core/index.css" />
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <div id="photosphere"></div>

        <script type="importmap">
            {
                "imports": {
                    "three": "/node_modules/three/build/three.module.js",
                    "@photo-sphere-viewer/core": "/dist/core/index.module.js"
                }
            }
        </script>

        <script type="module">
            import { Viewer } from '@photo-sphere-viewer/core';

            const baseUrl = 'https://photo-sphere-viewer-data.netlify.app/assets/';

            const panos = [
                {
                    url: baseUrl + 'sphere.jpg',
                    caption: 'Parc national du Mercantour <b>&copy; Damien Sorel</b>',
                },
                {
                    url: baseUrl + 'sphere-test.jpg',
                    caption: 'Test sphere',
                },
            ];

            const viewer = new Viewer({
                container: 'photosphere',
                panorama: panos[0].url,
                caption: panos[0].caption,
                loadingImg: baseUrl + 'loader.gif',
                fisheye: 2,
                maxFov: 130,
                defaultZoomLvl: 0,
                defaultPitch: -Math.PI / 2,
                navbar: [
                    'zoom',
                    'move',
                    'download',
                    {
                        title: 'Change image',
                        className: 'custom-button',
                        content: '🔄',
                        onClick: (() => {
                            let i = 0;
                            return () => {
                                i = 1 - i;
                                viewer.setPanorama(panos[i].url, {
                                    position: {
                                        yaw: 0,
                                        pitch: -Math.PI / 2,
                                    },
                                    zoom: 0,
                                    caption: panos[i].caption,
                                    description: panos[i].description,
                                });
                            };
                        })(),
                    },
                    {
                        title: 'Random position',
                        className: 'custom-button',
                        content: '🔀',
                        onClick: () => {
                            viewer.animate({
                                yaw: (((Math.random() - 0.5) * 3) / 2) * Math.PI,
                                pitch: (((Math.random() - 0.5) * 3) / 4) * Math.PI,
                                zoom: Math.random() * 60 + 20,
                                speed: 1500,
                            });
                        },
                    },
                    'caption',
                    'fullscreen',
                ],
            });

            window.viewer = viewer;
        </script>
    </body>
</html>
